<template>
  <div class="app-container" v-loading="loading">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="卡基本信息" name="1">
        <BasicInfo :tab="1" @push="push" :activeId="activeId" ref="BasicInfo"></BasicInfo>
      </el-tab-pane>
      <el-tab-pane label="配置卡权益" name="2">
        <AllocateEquity
          :tab="2"
          @push="push"
          :activeId="activeId"
          :code2="code2"
          ref="AllocateEquity"
        ></AllocateEquity>
      </el-tab-pane>
      <el-tab-pane label="配置卡券" name="3">
        <ConfigureCoupons
          :tab="3"
          @push="push"
          :activeId="activeId"
          :code3="code3"
          ref="ConfigureCoupons"
        ></ConfigureCoupons>
      </el-tab-pane>
      <el-tab-pane label="关联医院" name="4">
        <!-- {{activeId}} -->
        <ConfigureCoupons
          :tab="4"
          @push="push"
          :activeId="activeId"
          :code4="code4"
          ref="ConfigureCoupons2"
        ></ConfigureCoupons>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { hospitalDropDown } from "@/api/doctorManage";
import BasicInfo from "./cadAssembly/BasicInfo.vue";
import AllocateEquity from "./cadAssembly/AllocateEquity.vue";
import ConfigureCoupons from "./cadAssembly/ConfigureCoupons.vue";
export default {
  name: "AddPlatformCard",
  components: { BasicInfo, AllocateEquity, ConfigureCoupons },
  data() {
    return {
      reset: true,
      activeName: "1",
      hospOptions: [],
      loading: false,
      params: {},
      keeper: [],
      project: [],
      doctor: [],
      ischeck: ["", "", "", ""],
        code2: "",
        code3: "",
        code4: "",
      activeId: this.$route.query.userId-0
    };
    ss;
  },
  mounted() {
    this.userId = this.$route.query.userId - 0;
    this.type = this.$route.query.type;
    if (this.type == "edit") {
      this.$route.meta.title = "编辑平台卡";
    } else {
      this.$route.meta.title = "添加平台卡";
    }
    this.list();
  },
  methods: {
    list() {
      hospitalDropDown().then(res => {
        let resData = res.data.data;
        // let newData = [];
        // resData.forEach(e => {
        //   newData.push({
        //     value: e.id + "",
        //     label: e.name
        //   });
        // });
        this.hospOptions = resData;
        this.loading = false;
      });
    },
    // 没有填写基础信息时返回基础信息提示消息
    showMsg() {
      this.$message({
        showClose: true,
        message: "请先填写基本信息",
        type: "warning"
      });
      this.activeName = "1";
    },
    // 4个tab页面都提交成功后返回列表
    handleBack() {
      if (this.activeId&&this.code2&&this.code3&&this.code4) {
        this.$router.push("/platformCard");
      }
    },
    // 配置信息
    push(tab, id, only) {
      console.log(tab);
      // this.activeName = tab + 1 + "";
      console.log("id", id);
      this.activeId = id ? id : this.userId;
      console.log("activeId", this.activeId);

      // this.$refs.ConfigureCoupons2.getHospitalList(id);
      // this.$refs.ConfigureCoupons.handleCoupons(id);
      this.$refs.ConfigureCoupons.get_card_bind(id);
      if (tab == 1) {
        // if (id) {
        this.activeName = tab + 1 + "";

        // }
        // console.log("activeId", this.activeId);
      } else if (tab == 2) {
        if (id) {
          this.activeName = tab + 1 + "";
          this.code2=only
          this.handleBack();
        } else {
          this.showMsg();
        }
      } else if (tab == 3) {
        if (id) {
          this.$refs.ConfigureCoupons2.getHospitalList();

          this.activeName = tab + 1 + "";
          this.code3=only

          this.handleBack();
        } else {
          this.showMsg();
        }
      } else if (tab == 4) {
        if (id) {
          // this.activeName = tab;
          this.code4=only

          console.log(888);
          this.handleBack();
        } else {
          this.showMsg();
        }
      }
    },
    handleClick(tab, event) {
      console.log(this.activeName);
    }
  }
};
</script>
<style scoped>
.app-container {
  padding: 0.1px !important;
}
.el-textarea__inner {
  display: block;
  width: 300px !important;
  min-height: 50px !important;
  box-sizing: border-box;
}
</style>
